package com.action;

import com.auth.JwtUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/admin")
public class LoginAction {

    @RequestMapping("/login")
    public String login(String username, String password, HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
        if (username!=null && username.equals(password))
        {
            String token = JwtUtil.generToken(username,null,null);
            System.out.println(token);
            response.addHeader("token",token);
            return "success";
        }
        return "error";
    }
}
